<template>
<el-dialog :visible.sync="visible" title="回复消息" v-if="visible">
  <el-form :model="formData" label-position="right" label-width="80px" :rules="rules" ref="formData">
    <el-form-item label="反馈人">
      <el-input readonly v-if="formData.userId === undefined" value="匿名"/>
      <el-input readonly v-else :value="formData?.vip?.name"/>
    </el-form-item>
    <el-form-item label="反馈内容">
      <el-input type="textarea" :rows="3" placeholder="请输入内容" v-model="formData.content" readonly>
      </el-input>
    </el-form-item>
    <el-form-item label="回复内容" prop="reply">
      <el-input type="textarea" :rows="3" placeholder="请输入内容" v-model="formData.reply" maxlength="200" show-word-limit>
      </el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="update">提交</el-button>
      <el-button type="warning" @click="visible = false">取消</el-button>
    </el-form-item>
  </el-form>
</el-dialog>
</template>

<script>
export default {
  name: 'FeedbackUpdate',
  data () {
    return {
      visible: false,
      formData: {},
      rules: {
        reply: [{
          required: true,
          message: '请输入回复内容',
          trigger: 'blur'
        }]
      }
    }
  },
  methods: {
    init (id) {
      this.visible = true
      if (id) {
        this.$http.get(`feedback/info/${id}`).then(({ data }) => {
          this.formData = { ...data }
        })
      }
    },
    update () {
      this.$refs.formData.validate(valid => {
        if (valid) {
          this.formData.status = 2
          this.$http.post('feedback/update', this.formData).then(() => {
            this.$alert('回复成功', { type: 'success' }).then(() => {
              this.visible = false
              this.$emit('onCloseDialog')
            })
          })
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
